<template>
	<view>
		<view class="header flex">
			<image :src="imgurl+'search.png'"></image>
			<input class="inputcss" :class="[showcel==false?'':'otherinput']" placeholder="搜索问卷模板" placeholder-class="placeholder"
			 @focus="getFocus" confirm-type="search" @confirm="getTitle" v-model="searchtitle" />
			<view class="cancel" @tap="Cancel" v-if="showcel">取消</view>
		</view>
		<scroll-view scroll-x="true" class="scroll">
			<view :class="[currentTab==index ? 'select' : '',scrolltitle]" :data-current="index" :data-id="item.moid" @tap="swichNav"
			 v-for="(item,index) in scollList" :key="index">{{item.moname}}</view>
		</scroll-view>
		<swiper :current="currentTab" @change="bindChange" class='swp' :style="{height:aheight+'px'}">
			<swiper-item v-for="(item,index) in scollList" :key="index">
				<scroll-view scroll-y="true" style="height: 100%;">
					<view class="main flex">
						<view class="main-item row" @tap="CreateKongsur">
							<image :src="imgurl+'add.png'"></image>
							<text>从空白创建</text>
						</view>
						<view class="main-item row" @tap="editQuest">
							<image :src="imgurl+'add.png'"></image>
							<text>导入问卷</text>
						</view>
						<view class="main-item row" v-for="(item,index) in list" :key="index" @tap="creteSurDetail(item.id)">
							<span>{{item.name}}</span>
							<text>共{{item.shu!=null?item.shu:''}}题</text>
						</view>
					</view>
				</scroll-view>
			</swiper-item>

		</swiper>
	</view>
</template>

<script>
	import api from "@/common/api.js"
	import {
		baseURL
	} from "@/common/http.js";
	import app from "../../../App.vue"
	export default {
		data() {
			return {
				imgurl: "",
				showcel: false,
				currentTab: 0,
				aheight: "",
				scollList: [],
				moid: 2,
				list: [],
				searchtitle: ''
			};
		},
		methods: {
			//搜索问卷
			getTitle() {

			},
			getFocus() {
				this.showcel = true
			},
			Cancel() {
				this.showcel = false
			},
			//点击跳转至创建空白调查
			CreateKongsur() {
				uni.navigateTo({
					url: '../createKongVote/createKongVote?type=' + '3'
				})
			},
			//导入问卷
			editQuest() {
				uni.navigateTo({
					url: '../../questionType/textLeadin/textLeadin'
				})
			},
			// 滑动页面同步tab栏
			bindChange: function(e) {
				this.currentTab = e.detail.current
			},
			creteSurDetail(id) {
				uni.navigateTo({
					url: '../../creteSurDetail/creteSurDetail?id=' + id
				})
			},
			//点击tab切换
			swichNav: function(e) {
				var that = this;
				console.log(e)
				this.moid = e.target.dataset.id
				if (this.currentTab === e.target.dataset.current) {
					return false;
				} else {
					this.currentTab = e.target.dataset.current
				}
				let datas = {
					api: 'wenmocha',
					moid: this.moid
				}
				api.look(datas).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.list = res.date
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad() {
			this.imgurl = app.globalData.imgurls
		},
		onShow() {
			let that = this
			uni.getSystemInfo({
				success(res) {
					that.aheight = res.windowHeight * 0.85
				}
			})
			api.look({
				api: 'wenmo',
				lei: '投票'
			}).then(res => {
				console.log(res)
				if (res.code == 200) {
					this.scollList = res.date
				}
				this.scollList.unshift({
					moid: 2,
					moname: "默认模板"
				})
			}).catch(err => {
				console.log(err)
			})
			let datas = {
				api: 'wenmocha',
				moid: this.moid
			}
			api.look(datas).then(res => {
				console.log(res)
				if (res.code == 200) {
					this.list = res.date
				}
			}).catch(err => {
				console.log(err)
			})
		},
	}
</script>

<style lang="scss">
	page {
		background: #F0F0F0;
		font-weight: 500rpx;
		font-family: PingFang SC;
	}

	.placeholder {
		color: #999;
	}

	.header {
		justify-content: center;
		padding: 20rpx 0;
		background: #fff;
		position: relative;

		image {
			width: 50rpx;
			height: 50rpx;
			position: absolute;
			left: 5%;
			top: 30rpx;
		}

		.inputcss {
			background: F0F0F0;
			width: 690rpx;
			height: 60rpx;
			line-height: 60rpx;
			border-radius: 30rpx;
			color: #333;
			padding-left: 7%;
			box-sizing: border-box;
			background: #F0F0F0;
		}

		.otherinput {
			width: 615rpx;
		}

		.cancel {
			color: #666;
			font-size: 32rpx;
			margin-left: 10rpx
		}
	}

	.scroll {
		width: 96%;
		white-space: nowrap;
		padding: 25rpx 2%;
		background: #fff;
		font-size: 30rpx;

		& view {
			white-space: normal;
			display: inline-block;
		}

		& view:before {
			content: '|';
			color: #f4f4f4;
			margin: 0 30rpx;
		}

		& view:first-child:before {
			display: none;
		}

		.select {
			color: #209FFC;
		}
	}

	.main {
		display: flex;
		flex-wrap: wrap;
		width: 740rpx;
		margin: 0 auto;

		.main-item {
			justify-content: center;
			align-items: center;
			background: #fff;
			width: 330rpx;
			height: 300rpx;
			margin: 20rpx;
			box-shadow: 0px 5px 10px 0px #F0F0F0;

			image {
				width: 80rpx;
				height: 80rpx;
			}

			span {
				width: 224rpx;
				display: inline-block;
			}

			text {
				width: 224rpx;
				display: inline-block;
				text-align: center;
				font-size: 30rpx;
				color: #333;
			}
		}
	}
</style>
